﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MahApps.Metro.Controls;

namespace MauThuTabControl
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
          public bool fagDVT;
        public bool fagNhom;
         public bool fagSP;
        public bool fagKH;
         public bool fagTK;

         public bool fagHSX;
         public bool fagNH;
         public bool fagXH;
       
        public MainWindow()
        {
            InitializeComponent();
            tabControl1.Visibility = Visibility.Collapsed;

        }
      

        void dong()
        {
            _btDMSanPham.Visibility = System.Windows.Visibility.Hidden;
            _btTonKho.Visibility = System.Windows.Visibility.Hidden;
            button3.Visibility = System.Windows.Visibility.Hidden;
            _btKhachHang.Visibility = System.Windows.Visibility.Hidden;
            _btTimKiem.Visibility = System.Windows.Visibility.Hidden;
            button6.Visibility = System.Windows.Visibility.Hidden;
        }

        void mo()
        {
            _btDMSanPham.Visibility = System.Windows.Visibility.Visible;
           _btTonKho.Visibility = System.Windows.Visibility.Visible;
            button3.Visibility = System.Windows.Visibility.Visible;
            _btKhachHang.Visibility = System.Windows.Visibility.Visible;
            _btTimKiem.Visibility = System.Windows.Visibility.Visible;
            button6.Visibility = System.Windows.Visibility.Visible;
        }

       

        //private void tabItemCloseButton_Click(object sender, RoutedEventArgs e)
        //{
        //    DependencyObject obj = sender as DependencyObject;

        //    while (!(obj is TabItem))
        //    {
        //        obj = VisualTreeHelper.GetParent(obj);

        //    }

        //    tabControl1.Items.Remove(obj);
            
        //    if (tabControl1.Items.Count==0) 
        //    {
        //        mo();
        //        //button1.Visibility = System.Windows.Visibility.Visible;
        //        tabControl1.Visibility = System.Windows.Visibility.Collapsed;
        //    }
            
        //}

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            dong();
            if (fagDVT == true)
            {
                
                tabControl1.Items.Add(_TapDVT);
                fagDVT = false;
                _TapDVT.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapDVT;
                
            }
            else
            {
                tabControl1.SelectedItem =_TapDVT;
                _TapDVT.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
            //tabControl1.Visibility = System.Windows.Visibility.Visible;
           
            //    TabItem newTab = new TabItem();

               

            //    newTab.Header = "Đơn vị tính";
            //    newTab.IsSelected = true;
            //    tabControl1.Items.Add(newTab);

            //    newTab.Content = new Frame
            //    {
            //        Source = new Uri("NH.xaml", UriKind.Relative)
            //    };
           
                
                // button1.Visibility = System.Windows.Visibility.Hidden;
            
        }

        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
           dong();

            if (fagNhom == true)
            {
               tabControl1.Items.Add(_TapNhom);
                fagNhom = false;
                _TapNhom.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapNhom;
            }
            else
            {
                tabControl1.SelectedItem = _TapNhom;
                _TapNhom.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
            //tabControl1.Visibility = System.Windows.Visibility.Visible;
            //TabItem newTab = new TabItem();
            //newTab.Header = "Nhóm hàng";
            //newTab.IsSelected = true;
            //tabControl1.Items.Add(newTab);

            //newTab.Content = new Frame
            //{
            //    Source = new Uri("NhomHang.xaml", UriKind.Relative)
            //};
            //button1.Visibility = System.Windows.Visibility.Hidden;
        }

        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
        {
            dong();

            if (fagSP == true)
            {
                tabControl1.Items.Add(_TapSP);
                fagSP = false;
                _TapSP.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapSP;
            }
            else
            {
                tabControl1.SelectedItem = _TapSP;
                _TapSP.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        

        private void MenuItem_Click_3(object sender, RoutedEventArgs e)
        {
            dong();

            if (fagKH == true)
            {
                tabControl1.Items.Add(_TapKH);
                fagKH = false;
                _TapKH.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapKH;
            }
            else
            {
                tabControl1.SelectedItem = _TapKH;
                _TapKH.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void MenuItem_Click_4(object sender, RoutedEventArgs e)
        {
            dong();

            if (fagTK == true)
            {
                tabControl1.Items.Add(_TapTK);
                fagTK = false;
                _TapTK.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapTK;
            }
            else
            {
                tabControl1.SelectedItem = _TapTK;
                _TapTK.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void _btTimKiem_Click(object sender, RoutedEventArgs e)
        {
            dong();
            if (fagTK == true)
            {
                tabControl1.Items.Add(_TapTK);
                fagTK = false;
                _TapTK.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapTK;
            }
            else
            {
                tabControl1.SelectedItem = _TapTK;
                _TapTK.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void _btKhachHang_Click(object sender, RoutedEventArgs e)
        {
            dong();
            if (fagKH == true)
            {
                tabControl1.Items.Add(_TapKH);
                fagKH = false;
                _TapKH.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapKH;
            }
            else
            {
                tabControl1.SelectedItem = _TapKH;
                _TapKH.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void _btDMSanPham_Click(object sender, RoutedEventArgs e)
        {
            dong();
            if (fagSP == true)
            {
                tabControl1.Items.Add(_TapSP);
                fagSP = false;
                _TapSP.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapSP;
            }
            else
            {
                tabControl1.SelectedItem = _TapSP;
                _TapSP.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void _btCloseDVT_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapDVT);
            _TapDVT.Visibility = Visibility.Collapsed;
            fagDVT = true;
            if (_TapNhapHang.Visibility == Visibility.Collapsed && _TapXuatHang.Visibility == Visibility.Collapsed && _TapHSX.Visibility == Visibility.Collapsed && _TapSP.Visibility == Visibility.Collapsed && _TapKH.Visibility == Visibility.Collapsed && _TapNhom.Visibility == Visibility.Collapsed && _TapTK.Visibility == Visibility.Collapsed)
            {
                mo();
                
                tabControl1.Visibility = Visibility.Collapsed;
            }
        }

        private void _btCloseNhom_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapNhom);
            _TapNhom.Visibility = Visibility.Collapsed;
            fagNhom = true;
            if (_TapNhapHang.Visibility == Visibility.Collapsed && _TapXuatHang.Visibility == Visibility.Collapsed && _TapHSX.Visibility == Visibility.Collapsed && _TapDVT.Visibility == Visibility.Collapsed && _TapKH.Visibility == Visibility.Collapsed && _TapSP.Visibility == Visibility.Collapsed && _TapTK.Visibility == Visibility.Collapsed)
            {
                mo();
               
                tabControl1.Visibility = Visibility.Collapsed;
            }
        }

        private void _btCloseTK_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapTK);
            _TapTK.Visibility = Visibility.Collapsed;
            fagTK = true;
            if (_TapNhapHang.Visibility == Visibility.Collapsed && _TapXuatHang.Visibility == Visibility.Collapsed && _TapHSX.Visibility == Visibility.Collapsed && _TapDVT.Visibility == Visibility.Collapsed && _TapKH.Visibility == Visibility.Collapsed && _TapNhom.Visibility == Visibility.Collapsed && _TapSP.Visibility == Visibility.Collapsed)
            {
                mo();

                tabControl1.Visibility = Visibility.Collapsed;
            }
        }

        private void _btCloseKH_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapKH);
            _TapKH.Visibility = Visibility.Collapsed;
            fagKH = true;
            if (_TapNhapHang.Visibility == Visibility.Collapsed && _TapXuatHang.Visibility == Visibility.Collapsed && _TapHSX.Visibility == Visibility.Collapsed && _TapDVT.Visibility == Visibility.Collapsed && _TapSP.Visibility == Visibility.Collapsed && _TapNhom.Visibility == Visibility.Collapsed && _TapTK.Visibility == Visibility.Collapsed)
            {
                mo();

                tabControl1.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void _btCloseSP_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapSP);
            _TapSP.Visibility = Visibility.Collapsed;
            
            fagSP = true;
            if (_TapNhapHang.Visibility == Visibility.Collapsed && _TapXuatHang.Visibility == Visibility.Collapsed && _TapHSX.Visibility == Visibility.Collapsed && _TapDVT.Visibility == Visibility.Collapsed && _TapKH.Visibility == Visibility.Collapsed && _TapNhom.Visibility == Visibility.Collapsed && _TapTK.Visibility == Visibility.Collapsed)
            {
                mo();

                tabControl1.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void _btCloseHSX_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapHSX);
            _TapHSX.Visibility = Visibility.Collapsed;

            fagHSX = true;
            if (_TapNhapHang.Visibility == Visibility.Collapsed && _TapXuatHang.Visibility == Visibility.Collapsed && _TapDVT.Visibility == Visibility.Collapsed && _TapKH.Visibility == Visibility.Collapsed && _TapNhom.Visibility == Visibility.Collapsed && _TapTK.Visibility == Visibility.Collapsed && _TapSP.Visibility == Visibility.Collapsed)
            {
                mo();

                tabControl1.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void MenuItem_Click_5(object sender, RoutedEventArgs e)
        {
            dong();
            if (fagHSX == true)
            {
                tabControl1.Items.Add(_TapHSX);
                fagHSX = false;
                _TapHSX.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapHSX;

            }
            else
            {
                tabControl1.SelectedItem = _TapHSX;
                _TapHSX.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void _btCloseNH_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapNhapHang);
            _TapNhapHang.Visibility = Visibility.Collapsed;

            fagNH = true;
            if (_TapXuatHang.Visibility == Visibility.Collapsed && _TapDVT.Visibility == Visibility.Collapsed && _TapKH.Visibility == Visibility.Collapsed && _TapNhom.Visibility == Visibility.Collapsed && _TapTK.Visibility == Visibility.Collapsed && _TapSP.Visibility == Visibility.Collapsed)
            {
                mo();

                tabControl1.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void _btClosXH_Click(object sender, RoutedEventArgs e)
        {
            tabControl1.Items.Remove(_TapXuatHang);
            _TapXuatHang.Visibility = Visibility.Collapsed;

            fagXH = true;
            if (_TapNhapHang.Visibility == Visibility.Collapsed && _TapDVT.Visibility == Visibility.Collapsed && _TapKH.Visibility == Visibility.Collapsed && _TapNhom.Visibility == Visibility.Collapsed && _TapTK.Visibility == Visibility.Collapsed && _TapSP.Visibility == Visibility.Collapsed)
            {
                mo();

                tabControl1.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void _mnXH_Click(object sender, RoutedEventArgs e)
        {
            dong();
            if (fagXH == true)
            {
                tabControl1.Items.Add(_TapXuatHang);
                fagXH = false;
                _TapXuatHang.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapXuatHang;

            }
            else
            {
                tabControl1.SelectedItem = _TapXuatHang;
                _TapXuatHang.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void _mnNH_Click(object sender, RoutedEventArgs e)
        {
            dong();
            if (fagNH == true)
            {
                tabControl1.Items.Add(_TapNhapHang);
                fagNH = false;
                _TapNhapHang.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
                tabControl1.SelectedItem = _TapNhapHang;

            }
            else
            {
                tabControl1.SelectedItem = _TapNhapHang;
                _TapNhapHang.Visibility = Visibility.Visible;
                tabControl1.Visibility = Visibility.Visible;
            }
        }

        private void _btTonKho_Click(object sender, RoutedEventArgs e)
        {
            BCThongKeTonKho TK = new BCThongKeTonKho();
            TK.ShowDialog();
        }

        private void MenuItem_Click_6(object sender, RoutedEventArgs e)
        {
            BCThongKeTonKho TK = new BCThongKeTonKho();
            TK.ShowDialog();
        }

      
     

        
    }
}
